﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyHealthOnline.Business;

namespace MyHealthOnline.Administrators
{
    public partial class ManageQuestionnaires : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            int questionnaireId= QuestionnaireBusiness.CreateQuestionnaire(txtTitle.Text);
            grdQuestionnaires.DataBind();
            txtTitle.Text = "";

            updQuestionnaires.Update();
        }

        protected void grdQuestionnaires_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int index=Convert.ToInt32(e.CommandArgument);
            int id = Convert.ToInt32(grdQuestionnaires.DataKeys[index].Value);
            if (e.CommandName == "Edit")
            {
                //grdQuestionnaires.EditIndex = index;
                Response.Redirect("~/Administrator/OpenQuestionnaire.aspx?QuestionnaireId=" + id.ToString());
            }
            else if (e.CommandName == "Delete")
            {
                QuestionnaireBusiness.DeleteQuestion(id);
                grdQuestionnaires.DataBind();
                updQuestionnaires.Update();
            }
        }
    }
}